package rest_cli

import (
	"crypto/md5"
	"encoding/hex"
	"gluenet/modules/manager/server/domain/dependency"
	"gluenet/modules/manager/server/domain/entity"
	"gluenet/modules/manager/server/infra/prepare"

	"gopkg.in/yaml.v3"
)

func init() {
	prepare.RegisterRepo(func() {
		repo := NewGuidCLI()
		prepare.InjectDependency(func() dependency.GuidCLI {
			return repo
		})
	})
}

type Guid struct {
}

func (g *Guid) Register(ordor *entity.RegisterOrder) (string, error) {
	ordor.OrderID = ""
	bts, err := yaml.Marshal(ordor)
	if err != nil {
		return "", err
	}
	d := md5.Sum(bts)
	guid := hex.EncodeToString(d[:])
	return guid, err
}

func (g *Guid) UnRegister(guid string) error {
	return nil
}

func NewGuidCLI() *Guid {
	r := &Guid{}
	return r
}
